home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Juegos Flash / jack_vs_kelly.dcr / 00034_animation.class.ls < prev    next >
Encoding:
Text File  |  2003-05-02  |  2.9 KB  |  107 lines

  1. property ancestor, p_parent, p_callback, p_callback_target, p_sprite_classes, p_sprites, p_animation_finished_count, p_sfx, p_sfx_time
  2.  
  3. on new me, parent, callback, callback_target, sprite_classes, sfx, sfx_time
  4.   me.p_parent = parent
  5.   me.p_callback = callback
  6.   me.p_callback_target = callback_target
  7.   me.p_sprites = []
  8.   me.p_sprite_classes = sprite_classes
  9.   me.p_sfx = sfx
  10.   me.p_sfx_time = sfx_time
  11.   return me
  12. end
  13.  
  14. on integrate me, delta_time
  15.   call(#integrate, me.p_sprites, delta_time)
  16. end
  17.  
  18. on start_sequence me
  19.   me.p_animation_finished_count = 0
  20.   sprite_states = me.get_initial_sprite_states()
  21.   me.sequence(sprite_states)
  22. end
  23.  
  24. on next_sequence me
  25.   me.p_animation_finished_count = 0
  26.   sprite_states = me.get_current_sprite_states()
  27.   me.sequence(sprite_states)
  28. end
  29.  
  30. on sequence me, sprite_states
  31.   me.p_sprites = []
  32.   i = 0
  33.   if not voidp(me.p_sfx_time) then
  34.     me.p_sfx_time = me.p_sfx_time - 1
  35.     if me.p_sfx_time = 0 then
  36.       sfx_play_sound(me.p_sfx)
  37.     end if
  38.   end if
  39.   repeat with curr_state in sprite_states
  40.     me.p_sprites.add(script(me.p_sprite_classes.getPropAt(1)).new(me, #animation_done, curr_state.image_name, curr_state.loc, curr_state.speed, me.p_sprite_classes[1] * i))
  41.     i = i + 1
  42.   end repeat
  43.   me.p_sprite_classes.deleteAt(1)
  44. end
  45.  
  46. on get_initial_sprite_states me
  47.   sprite_states = []
  48.   repeat with i = 1 to 7
  49.     sprite_states.add([#image_name: "letter_r", #loc: point(0, 0), #speed: point(0, 0)])
  50.   end repeat
  51.   return sprite_states
  52. end
  53.  
  54. on get_current_sprite_states me
  55.   sprite_states = []
  56.   repeat with curr_sprite in me.p_sprites
  57.     sprite_states.add([#image_name: curr_sprite.p_img_name, #loc: curr_sprite.p_loc, #speed: curr_sprite.p_speed])
  58.   end repeat
  59.   return sprite_states
  60. end
  61.  
  62. on animation_done me
  63.   me.p_animation_finished_count = me.p_animation_finished_count + 1
  64.   if me.p_animation_finished_count = me.p_sprites.count then
  65.     if me.p_sprite_classes.count > 0 then
  66.       me.next_sequence()
  67.     else
  68.       me.callback()
  69.     end if
  70.   end if
  71. end
  72.  
  73. on callback me
  74.   if objectp(me.p_callback_target) then
  75.     if symbolp(me.p_callback) then
  76.       call(me.p_callback, me.p_callback_target)
  77.     end if
  78.   end if
  79. end
  80.  
  81. on draw_sprites me, buffer
  82.   repeat with curr_sprite in p_sprites
  83.     curr_loc = me.translate_loc(curr_sprite.p_loc, buffer)
  84.     dest_rect = rect(curr_loc[1], curr_loc[2], curr_loc[1] + curr_sprite.p_src_img.width, curr_loc[2] + curr_sprite.p_src_img.height)
  85.     buffer.copyPixels(curr_sprite.p_src_img, dest_rect, curr_sprite.p_src_img.rect, [#ink: 8, #matte: curr_sprite.p_matte])
  86.   end repeat
  87.   return buffer
  88. end
  89.  
  90. on translate_loc me, rel_loc, buffer
  91.   abs_loc = point(rel_loc[1] + (buffer.width / 2), rel_loc[2] + (buffer.height / 2))
  92.   return abs_loc
  93. end
  94.  
  95. on dispose me
  96.   me.p_parent = VOID
  97.   me.p_callback = VOID
  98.   me.p_callback_target = VOID
  99.   call(#dispose, me.p_sprites)
  100.   me.p_sprites = VOID
  101.   me.p_sprite_classes = VOID
  102.   me.p_animation_finished_count = VOID
  103.   me.p_sfx = VOID
  104.   me.p_sfx_time = VOID
  105.   callAncestor(#dispose, [me])
  106. end
  107.